// pages/scoreanalysis/scoreanalysis.js
import http from '../../utils/requestAnalysis'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        launchFlag: true,
        selectMenu: {},
        height: null,
        totalScoreFlag: true,
        switch: true,
        criticalGrowth: [],
        criticalGrowthObj: {},
        oneBooks: {},
        twoBooks: {},
        goOnlineFlag: true,
        criticalGrowthFlag: true,
        scoringRateData: [],
        onlineComparisonData: [],
        rankingSegmentHead: [],
        rankingSegmentData: [],
        fractionalRangeHead: [],
        fractionalRangeData: [],
        yData: [
            {
                name: '班级',
                data: [10,20,30,40]
            },
            {
                name: '学校',
                data:[1,2,3,4]
            }
        ],
        xData: ['优秀','良好','及格','低分'],
        menuList: [],
        onLine1Score: null,
        onLine2Score: null,
        schoolReferenceNumber: null,
        schoolAverageScore: null,
        schoolMaximumScore: null,
        schoolAverageScoreRanking: null,
        schoolExcellenceRate: null,
        schoolPassingRate: null,
        numberOfJointExaminations:null,//联考人数
        averageScoreOfTheJointExamination: null,//联考平均分
        theHighestScoreInTheJointExam:null,//联考最高分
        fullScore: 750,
        averageScoreX: [],
        averageScoreY: [],
        averageScoreData: [],
        aline: null,
        bline: null,
        selectName:'总分'
    },
    changeMenu(e) {
        //console.log(e.detail, 'sssssssssssssssss');
        this.setData({
            selectMenu: e.detail,
            selectName:e.detail.subjectName
        })
        this.getExamOverview()
        if (e.detail.subjectName.indexOf('总分') > -1) {
            this.setData({
                totalScoreFlag: true
            })
            this.getOnlineRate()
            this.analysisAllScoreOnlineComparator()
            // this.analysisAllScoreOnlineCritical()
            this.analysisAppAllScoreOnlineCritical()
            // this.totalScoreRankingSegment()
            this.comparisonOfMeanScores()
            this.totalScoreFractionalRange()
            if (this.data.selectMenu.navType == 0) {
                // 总分不赋分
                this.totalScoreScoringRate()
                
            }
        } else {
            this.setData({
                totalScoreFlag: false
            })
            this.singleDisciplineComparisonOfMeanScores()
            this.monofamilyRankingSegment()
            this.monofamilyFractionalRange()
            if (this.data.selectMenu.navType == 0) {
                // 单科不赋分
                this.monofamilyScoringRate()
            }
        }
    },
    changeoverSwitch() {
        this.setData({
            switch: !this.data.switch
        })
    },
    async getSchoolSubject() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        //console.log(datalist, 'looooooooooooooooooooooooool')
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/subject/list',
                method: 'POST',
                data: {
                    navId: datalist.n5,
                    groupId: datalist.groupid,
                    groupType: 0
                },
                header: {
                    "content-type": "application/json"
                }
            }
            let res = await http(options)
            //console.info(res)
            if (res.data.code == 0) {
                let data = res.data.data
                data.map(res => {
                    if (res.subjectName.indexOf('总分') > -1) {
                        res.totalscoreflag = true
                    } else {
                        res.totalscoreflag = false
                    }
                })
                this.setData({
                    menuList: data,
                    selectMenu: data[0]
                })
                this.getExamOverview()
                // 判断是单科还是总分
                if (data[0].subjectName.indexOf('总分') > -1) {
                    this.setData({
                        totalScoreFlag: true
                    })
                    this.getOnlineRate()
                    this.analysisAllScoreOnlineComparator()
                    // this.analysisAllScoreOnlineCritical()
                    this.analysisAppAllScoreOnlineCritical()
                    // this.totalScoreRankingSegment()
                    this.comparisonOfMeanScores()
                    this.totalScoreFractionalRange()
                    if (this.data.selectMenu.navType == 0) {
                        // 总分不赋分
                        this.totalScoreScoringRate()
                    }
                } else {
                    this.setData({
                        totalScoreFlag: false
                    })
                    this.singleDisciplineComparisonOfMeanScores()
                    this.monofamilyRankingSegment()
                    this.monofamilyFractionalRange()
                    if (this.data.selectMenu.navType == 0) {
                        // 单科不赋分
                        this.monofamilyScoringRate()
                    }
                }
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 考试总览
    async getExamOverview() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        //console.log(datalist, 'looooooooooooooooooooooooool')
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/school/score/overview',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.subjectName.indexOf('总分') > -1 ? datalist.n5 : this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    navType:this.data.selectMenu.navType
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                this.setData({
                    schoolReferenceNumber:data.people,
                    schoolAverageScore:data.avgScore,
                    schoolMaximumScore:data.maxScore,
                    schoolAverageScoreRanking:data.examView.examRank,
                    schoolExcellenceRate:data.goodRate,
                    schoolPassingRate:(data.passRate*100).toFixed(2),
                    numberOfJointExaminations: data.examView ? data.examView.examPeople : null,
                    averageScoreOfTheJointExamination:data.examView ? data.examView.examAvgScore : null,
                    theHighestScoreInTheJointExam:data.examView ? data.examView.maxScore : null,
                    fullScore: data.fullScore
                })
                if (data.aline == null) {
                    this.setData({
                        aline:'一本线'
                    })
                } else if (data.aline == 0) {
                    this.setData({
                        aline:'清北线'
                    })
                } else if (data.aline == 1) {
                    this.setData({
                        aline:'强基线'
                    })
                } else if (data.aline == 2) {
                    this.setData({
                        aline:'600分线'
                    })
                } else if (data.aline == 3) {
                    this.setData({
                        aline:'985线'
                    })
                } else if (data.aline == 4) {
                    this.setData({
                        aline:'211线'
                    })
                } else if (data.aline == 5) {
                    this.setData({
                        aline:'特控线(一本线)'
                    })
                } else if (data.aline == 6) {
                    this.setData({
                        aline:'一本线'
                    })
                } else if (data.aline == 7) {
                    this.setData({
                        aline:'二本线'
                    })
                } else if (data.aline == 8) {
                    this.setData({
                        aline:'本科线'
                    })
                } else if (data.aline == 9) {
                    this.setData({
                        aline:'专科线'
                    })
                }
                if (data.bline == null) {
                    this.setData({
                        bline:'二本线'
                    })
                } else if (data.bline == 0) {
                    this.setData({
                        bline:'清北线'
                    })
                } else if (data.bline == 1) {
                    this.setData({
                        bline:'强基线'
                    })
                } else if (data.bline == 2) {
                    this.setData({
                        bline:'600分线'
                    })
                } else if (data.bline == 3) {
                    this.setData({
                        bline:'985线'
                    })
                } else if (data.bline == 4) {
                    this.setData({
                        bline:'211线'
                    })
                } else if (data.bline == 5) {
                    this.setData({
                        bline:'特控线(一本线)'
                    })
                } else if (data.bline == 6) {
                    this.setData({
                        bline:'一本线'
                    })
                } else if (data.bline == 7) {
                    this.setData({
                        bline:'二本线'
                    })
                } else if (data.bline == 8) {
                    this.setData({
                        bline:'本科线'
                    })
                } else if (data.bline == 9) {
                    this.setData({
                        bline:'专科线'
                    })
                }
                if (this.data.selectMenu.subjectName.indexOf('总分') > -1) {
                    this.totalScoreRankingSegment()
                }
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 总分上线率
    async getOnlineRate() {
        if (!this.data.launchFlag) {
            return
        }
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/allScore/online/rate',
                method: 'POST',
                data: {
                    navId: datalist.n5,
                    groupId: datalist.groupid,
                    lineType: 0
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                this.setData({
                    onLine1Score: data.onLine1Score,
                    onLine2Score: data.onLine2Score,
                    oneBooks: {
                        onLineNum: data.onLine1Num,
                        onLineRate: data.onLine1Rate,
                        onLineScore: data.onLine1Score,
                    },
                    twoBooks: {
                        onLineNum: data.onLine2Num,
                        onLineRate: data.onLine2Rate,
                        onLineScore: data.onLine2Score,
                    },
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 总分平均分对比
    async comparisonOfMeanScores() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/school/allscore/avg',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.subjectName.indexOf('总分') > -1 ? datalist.n5 : this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    navType:this.data.selectMenu.navType
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                let x = []
                let y = []
                data.map(res => {
                    x.push(res.className)
                    y.push(res.avgScore)
                })
                this.setData({
                    averageScoreX: x,
                    averageScoreY: y,
                    averageScoreData: data
                })
                //console.log(this.data.averageScoreData,111111);
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 单科平均分对比
    async singleDisciplineComparisonOfMeanScores() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/average/score/by/subject',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.subjectName.indexOf('总分') > -1 ? datalist.n5 : this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    type: 0,
                    genExcel: 0,

                },
                header: {
                    "content-type": "application/json"
                }
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                // 判断当前科目是否是赋分
                if (this.data.selectMenu.navType == 1) {
                    // 赋分
                    let x = []
                    let y = []
                    let datas = []
                    data.ffAberageResoinseList.map((res,index) => {
                        if (index != 0 && index != 1) {
                            datas.push({
                                className: res.school,
                                people: res.examPeople,
                                maxScore: res.maxScore,
                                avgScore: res.averageScore,
                                rank: res.ranking
                            })
                            x.push(res.school)
                            y.push(res.averageScore)
                        }
                    })
                    this.setData({
                        averageScoreX: x,
                        averageScoreY: y,
                        averageScoreData: datas
                    })
                } else {
                    // 不赋分
                    let x = []
                    let y = []
                    let datas = []
                    data.averageResponseList.map((res,index) => {
                        if (index != 0 && index != 1) {
                            datas.push({
                                className: res.school,
                                people: res.examPeople,
                                maxScore: res.maxScore,
                                avgScore: res.averageScore,
                                rank: res.ranking
                            })
                            x.push(res.school)
                            y.push(res.averageScore)
                        }
                    })
                    this.setData({
                        averageScoreX: x,
                        averageScoreY: y,
                        averageScoreData: datas
                    })
                }
                //console.log(data,'111111cccccccccccccccccccccc');
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 上线人数对比
    async analysisAllScoreOnlineComparator() {
        if (!this.data.launchFlag) {
            return
        }
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/allScore/online/comparator',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.subjectName.indexOf('总分') > -1 ? datalist.n5 : this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    lineType: 0
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                if (data) {
                    this.setData({
                        goOnlineFlag: true
                    })
                } else {
                    this.setData({
                        goOnlineFlag: false
                    })
                }
                this.setData({
                    onlineComparisonData: data
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 临界生分析
    async analysisAllScoreOnlineCritical() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/allScore/online/critical',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.subjectName.indexOf('总分') > -1 ? datalist.n5 : this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    lineType: 0
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                this.setData({
                    criticalGrowth: data
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 临界生分析
    async analysisAppAllScoreOnlineCritical() {
        if (!this.data.launchFlag) {
            return
        }
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/app/allScore/online/critical',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.subjectName.indexOf('总分') > -1 ? datalist.n5 : this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    lineType: 0,
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                //console.log(data, 'rrrrrrrrrrrrrrrrrrrrrrrrrr')
                if (data) {
                    this.setData({
                        criticalGrowthFlag: true
                    })
                } else {
                    this.setData({
                        criticalGrowthFlag: false
                    })
                }
                this.setData({
                    criticalGrowthObj: data
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 总分名次段
    async totalScoreRankingSegment() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/allscore/rank/paragraph',
                method: 'POST',
                data: {
                    navId: datalist.n5,
                    groupId: datalist.groupid,
                    type: 0,
                    genExcel: 0,
                    rankRegionNum: 50
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                // //console.log(data,'cxxxxxxxxxxxxxxxxxxxx');
                let obj = {}
                if (this.data.selectMenu.navType == 1) {
                    obj = this.arrangeData(data.ffschoolAllScoreRankParagraphs)
                } else {
                    obj = this.arrangeData(data.schoolAllScoreRankParagraphs)
                }
                // //console.log(obj.arr,obj.headArr, 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnn');
                this.setData({
                    rankingSegmentHead: obj.headArr,
                    rankingSegmentData: obj.arr
                })
                //console.log(this.data.rankingSegmentHead,this.data.rankingSegmentData, 'ggggggggggggggggggggggggggggg')
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 单科名次段
    async monofamilyRankingSegment() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/rank/paragraph/by/subject',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    type: 0,
                    genExcel: 0,
                    rankRegionNum: 50
                },
                header: {
                    "content-type": "application/json"
                }
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                // //console.log(data,'cxxxxxxxxxxxxxxxxxxxx');
                let obj = {}
                if (this.data.selectMenu.navType == 1) {
                    obj = this.arrangeData(data.ffrankParagraphResponses)
                } else {
                    obj = this.arrangeData(data.rankParagraphResponses)
                }
                //console.log(obj.arr,obj.headArr, 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnn');
                this.setData({
                    rankingSegmentHead: obj.headArr,
                    rankingSegmentData: obj.arr
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 整理名次段分数段数据
    arrangeData(e) {
        let headArr = [] //表头
        let chartDatas = {}
        let arr = []
        setTimeout(() => {
            //console.log(this.data.schoolReferenceNumber,'>>>>>>>><<<<<<<<<<<<<>>>>>>>>>>>><<<<<<<<<<<<<<');
        },2000)
        for(let i = 0 ;i<Math.ceil(this.data.schoolReferenceNumber/50); i++) {
            headArr.push({
              title: '前'+(i+1) * 50+'名',
              value: 'thisParagraph' + (i+1),
            })
        }
        e.map((res,index) => {
            chartDatas[index] = []
            for(let i = 0 ;i<Math.ceil(this.data.schoolReferenceNumber/50); i++) {
              chartDatas[index].push(0)
            }
        })
        e.map((res,i) => {
            arr.push({school: res.school})
            res.eps.map((ress,index) => {
                chartDatas[i][ress.p - 1] = ress.pnum
            })
        })
        Object.keys(chartDatas).map((res,i) => {
            chartDatas[res].map((ress,index) => {
              if (index != 0) {
                chartDatas[res][index] = chartDatas[res][index - 1] + chartDatas[res][index]
                // chartDatas[res][index] = chartDatas[res][index]
              }
              arr[i]['thisParagraph' + (index+1)] = chartDatas[res][index]
            })
        })
        let obj = {
            arr:arr,
            headArr:headArr
        }
        return obj
    },
    // 总分分数段
    async totalScoreFractionalRange() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/allscore/paragraph',
                method: 'POST',
                data: {
                    navId: datalist.n5,
                    groupId: datalist.groupid,
                    type: 0,
                    genExcel: 0,
                    rankRegionNum: 50
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                // //console.log(data,'cxxxxxxxxxxxxxxxxxxxx');
                let obj = {}
                if (this.data.selectMenu.navType == 1) {
                    obj = this.arrangeDatas(data.ffschoolAllScoreParagraphs)
                } else {
                    obj = this.arrangeDatas(data.schoolAllScoreParagraphs)
                }
                //console.log(obj.arr,obj.headArr, 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnn222222222222222222');
                this.setData({
                    fractionalRangeHead: obj.headArr,
                    fractionalRangeData: obj.arr
                })
                // //console.log(this.data.rankingSegmentHead,this.data.rankingSegmentData, 'ggggggggggggggggggggggggggggg')
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 单科分数段
    async monofamilyFractionalRange() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/score/paragraph',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    type: 0,
                    genExcel: 0,
                    rankRegionNum: 50
                },
                header: {
                    "content-type": "application/json"
                }
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                let obj = {}
                if (this.data.selectMenu.navType == 1) {
                    obj = this.arrangeDatas(data.ffParagraphScoreResponses)
                } else {
                    obj = this.arrangeDatas(data.paragraphScoreResponses)
                }
                this.setData({
                    fractionalRangeHead: obj.headArr,
                    fractionalRangeData: obj.arr
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 整理分数段数据
    arrangeDatas(e) {
        let headArr = [] //表头
        let arr = []
        e.map((res,i) => {
            arr.push({school: res.school})
            res.eps.reverse()
        })
        e[0].eps.map((res,i) => {
            headArr.push({
              title: res.p * 50 - 50 + '-' + (res.p * 50),
              value1: 'thisParagraph' + i,
              value2: 'accumulate' + i
            })
            e.map((ress,index) => {
              ress.eps.map(resss => {
                if (resss.p == res.p) {
                  if (i == 0) {
                    arr[index]['thisParagraph' + i] = resss.pnum
                    arr[index]['accumulate' + i] = resss.pnum
                  } else {
                    arr[index]['thisParagraph' + i] = resss.pnum
                    arr[index]['accumulate' + i] = arr[index]['accumulate' + (i - 1)] ? arr[index]['accumulate' + (i - 1)] + resss.pnum : resss.pnum
                  }
                }
              })
            })
            for(let v = 0; v < e.length; v++) {
              if (i == 0) {
                if (arr[v]['thisParagraph' + i] && arr[v]['accumulate' + i]) {
                  // arr[v]['thisParagraph' + i] = 0
                  arr[v]['accumulate' + i] = arr[v]['thisParagraph' + i]
                } else {
                  arr[v]['thisParagraph' + i] = 0
                  arr[v]['accumulate' + i] = 0
                }
                
              } else {
                if (arr[v]['thisParagraph' + i] && arr[v]['accumulate' + i]) {
                  arr[v]['accumulate' + i] = arr[v]['accumulate' + (i - 1)] + arr[v]['thisParagraph' + i]
                } else {
                  arr[v]['thisParagraph' + i] = 0
                  arr[v]['accumulate' + i] = arr[v]['accumulate' + (i - 1)]
                }
              }
            }
        })
        let obj = {
            arr:arr,
            headArr:headArr
        }
        return obj
    },
    // 总分两分四率
    async totalScoreScoringRate() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/allscore/syn',
                method: 'POST',
                data: {
                    navId: datalist.n5,
                    groupId: datalist.groupid,
                    type: 0,
                    genExcel: 0,
                    rankRegionNum: 1
                },
                header: {
                    "content-type": "application/json"
                }
            }
            if (this.data.selectMenu.type4 != null) {
                options.data.type4 = [this.data.selectMenu.type4]
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                //console.log(data,'cxxxxxxxxxxxxxxxxxxxx');
                let data1 = []
                let data2 = []
                data.synIndicatrixResponses.map((res,index) => {
                    if (index == 0) {
                        data1 = [res.goodScoreRate,res.mediumScoreRate,res.passScoreRate,res.lowScoreRate]
                    }
                    if (index == 1) {
                        data2 = [res.goodScoreRate,res.mediumScoreRate,res.passScoreRate,res.lowScoreRate]
                    }
                })
                //console.log(data1,data2, 'gggggggggggggggggggggggg');
                this.setData({
                    yData: [
                        {
                            name: '联考',
                            data: data1
                        },
                        {
                            name: '学校',
                            data: data2
                        }
                    ],
                    scoringRateData: data.synIndicatrixResponses
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 单科两分四率
    async monofamilyScoringRate() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                datalist: datalist
            })
            let options = {
                url: '/analysis/syn/indicatrix',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.navId,
                    groupId: datalist.groupid,
                    type: 0,
                    genExcel: 0,
                },
                header: {
                    "content-type": "application/json"
                }
            }
            let res = await http(options)
            //console.info(res)
            let data = res.data.data
            if (res.data.code == 0) {
                //console.log(data,'cxxxxxxxxxxxxxxxxxxxx');
                let data1 = []
                let data2 = []
                let datas = []
                if (this.data.selectMenu.navType == 0) {
                    data.synIndicatrixResponses.map((res,index) => {
                        if (index == 0) {
                            data1 = [res.goodScoreRate,res.mediumScoreRate,res.passScoreRate,res.lowScoreRate]
                        }
                        if (index == 1) {
                            data2 = [res.goodScoreRate,res.mediumScoreRate,res.passScoreRate,res.lowScoreRate]
                        }
                    })
                    datas = data.synIndicatrixResponses
                } else {
                    data.ffsynIndicatrixResponses.map((res,index) => {
                        if (index == 0) {
                            data1 = [res.goodScoreRate,res.mediumScoreRate,res.passScoreRate,res.lowScoreRate]
                        }
                        if (index == 1) {
                            data2 = [res.goodScoreRate,res.mediumScoreRate,res.passScoreRate,res.lowScoreRate]
                        }
                    })
                    datas = data.ffsynIndicatrixResponses
                }
                this.setData({
                    yData: [
                        {
                            name: '联考',
                            data: data1
                        },
                        {
                            name: '学校',
                            data: data2
                        }
                    ],
                    scoringRateData: datas
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    // 获取联考是否有上线信息
    async getLaunchInformation() {
        let that = this
        let datalist = JSON.parse(wx.getStorageSync('alaynisData'))
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            let options = {
                url: '/group/list',
                method: 'POST',
                data: {
                    navId: datalist.n5,
                },
                header: {
                    "content-type": "application/json"
                }
            }
            let res = await http(options)
            //console.info(res,'l>>>>>>>>>>>>>>>>>>>>>>>>>>l')
            let data = res.data.data
            if (res.data.code == 0) {
                if (data.lknum1 == 0 && data.lknum2 == 0 && data.wknum1 == 0 && data.wknum2 == 0) {
                    that.setData({
                        launchFlag: false
                    })
                } else {
                    // 有上线信息
                    that.setData({
                        launchFlag: true
                    })
                }
                that.getSchoolSubject()
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newteacherlogin/newteacherlogin',
            })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getLaunchInformation()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        // setTimeout(() => {
        //     this.setData({
        //         yData: [20, 100, 50, 8, 7, 10, 30]
        //     })
        // }, 10000)
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let query = wx.createSelectorQuery()
        query.select('#myElements').boundingClientRect((rect) => {
            //console.log(rect, 'aaaaaaaaaaaaaaaaaaaaaaa');
            this.setData({
                height: rect.top + 10 +'px'
            })
                    
        }).exec()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})